let starBtn = document.querySelector(".starBtn");
let prizeCell = document.querySelectorAll(".drawBox div:not(.starBtn)");
let index = 0;
let targetIndex = 30;
let timer;
let second = 200;
let isRun = true;
let newisRun = true;
let jiangpin = document.querySelectorAll(".drawBox1 div");
let newIndex = 0;
let newTargetindex = 30;
//开始抽奖(基础版)
//starBtn.addEventListener("click",function(){
    // timer = setInterval(function(){
    //     if (index){
    //         prizeCell[(index -1 ) % 8].classList.remove("active");
    //     }
    //     prizeCell[index % 8].classList.add("active");

    //     if(index == targetIndex){
    //         clearInterval(timer)
    //     }
        
    //     index++;
    // },500)
    
//})


//开始抽奖（升级版）
starBtn.addEventListener("click",function(){
    if (isRun) {
        isRun = false;
        run();
        enen();
    }
})
function run (){
    setTimeout(function(){
        if (index){
            prizeCell[(index -1 ) % 8].classList.remove("active");
        }
        prizeCell[index % 8].classList.add("active");

        if (index < targetIndex){
            run();
        } else {
            isRun = true;
        }
        index++;

        if(second > 30 && index < 20){
            //加速
            second -= 20;
        }else if (index > 60){
            //减速
            second += 20;
        }
        
    },second)
}


//奖品展示
function enen (){
    setInterval(function(){
        if (newIndex){
            jiangpin[(newIndex -1 ) % 8].classList.remove("active");
        }
        jiangpin[newIndex % 8].classList.add("active");

        if (newIndex < newTargetindex){
            enen();
        } else {
            newisRun = true;
        }
        newIndex++;

        if(second > 30 && newIndex < 20){
            //加速
            second -= 20;
        }else if (newIndex > 60){
            //减速
            second += 20;
        }
        
    },second)
}

